#include"tree.h"
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

static TreeNode * TreeNode_construct(int value){

    TreeNode * node = malloc(sizeof(TreeNode));
    if(NULL == node){

        printf("malloc sizeof(TreeNode) failed.\n");
        return NULL;
    }
    node->left = NULL;
    node->right = NULL;
    node->value = value;

    return node;
}

TreeNode * Tree_insert(TreeNode * root,int value){

    if(NULL == root){

        return TreeNode_construct(value);
    }
    if(value == root->value){

        return root;
    }
    if(root->value < value){

        root->right = Tree_insert(root->right,value);
    }else{

        root->left = Tree_insert(root->left,value);
    }
    return root;
}

